<?xml version="1.0" encoding="utf-8"?>
<taskrunner name="desktop.shortcuts.rights" version="1.1" date="2009-03-28" maxthreads="1">

  <!--
  Windows VISTA does not always refresh the desktop icon cache when changes are made. One way to
  solve this problem is to delete the tow files iconcache.db and GDIPFONTCACHEV1.DAT. However, no
  visible changes on the desktop icons can be seen just by doing this. It also requiers a reboot of
  the system. One way to avoid a reboot is to trigger a restart of the windows gui component explorer.
  This is what this script does. A flag in the registry will restart the explorer shell as soon as it's
  terminated. 
  Check registry key HKEY_LOCAL_MACHINE\SOFTWARE\Microsoft\Windows NT\CurrentVersion\Winlogon\AutoRestartShell
  This value should be 1. If it's 0 then the explorer shell will not automatically restart when it terminates
  and this script will not work as it's supposed.
  -->

  <includes>
    <file name="vida.install.settings.xml" />
  </includes>

  <enumerations>
    <enum name="files">
      <item key="iconcache.db"/>
      <item key="GDIPFONTCACHEV1.DAT"/>
    </enum>
  </enumerations>


  <tasks>


    <task name="kill.explorer" condition="${windows.version.major}=6" typename="@KillProcess">
      <parameters>
        <parameter name="process" value="explorer"/>
      </parameters>
    </task>

    <task name="add.accesscontrol.to.install.root" critical="false">
      <description>
        Adds FullControl permission to the Vida install folder
        and it's subfolders to all users.
      </description>
      <dependencies list="autostart.items[requireSuccess=false]"/>
      <subtasks filename="vida.accesscontrol.xml">
        <parameters>
          <parameter name="fullpath" value="${target.root}"/>
        </parameters>
      </subtasks>
    </task>

    <task name="acl.programs" critical="false">
      <description>
        Grants FullControl for group Users to the Programs folder where the desktop shortcuts are stored.
      </description>
      <dependencies list="add.accesscontrol.to.install.root"/>
      <subtasks filename="vida.accesscontrol.xml">
        <parameters>
          <parameter name="fullpath" value="${windows.folders.programs.allusers}\${programs.subfolder}"/>
        </parameters>
      </subtasks>
    </task>

    <foreach enum="files">
      <task name="remove.attribute.hidden" allowMultipleInstances="true" typename="@CommandLine">
        <dependencies list="kill.explorer"/>
        <parameters>
          <parameter name="arguments" value="attrib -H $[files:key]"/>
          <parameter name="workingdirectory" value="${windows.folders.appdata}"/>
          <parameter name="useCmdExe" value="true"/>
        </parameters>
      </task>

      <task name="remove.iconcache.db" allowMultipleInstances="true" typename="@DeleteFile" retry="3" critical="true">
        <dependencies list="remove.attribute.hidden"/>
        <parameters>
          <parameter name="filename" value="${windows.folders.appdata}\$[files:key]"/>
        </parameters>
      </task>
    </foreach>

    <task name="refresh.desktop" condition="${windows.version.major}=6" typename="@RefreshDesktop" critical="false">
      <description>
        Windows Vista does not always refresh it's desktop after changes.
      </description>
      <dependencies list="remove.iconcache.db"/>
    </task>

    <foreach enum="desktop.shortcuts">
      
      <task name="acl.link" condition="$[desktop.shortcuts:addAclAllUsersDesktopShortcut]=true" allowMultipleInstances="true" critical="false">
        <description>
          Grants FullControl for group Users to the desktop shortcut.
        </description>
        <dependencies list="remove.iconcache.db,add.accesscontrol.to.install.root"/>
        <subtasks filename="vida.accesscontrol.xml">
          <parameters>
            <parameter name="fullpath" value="${windows.folders.desktop.allusers}\$[desktop.shortcuts:key].lnk"/>
          </parameters>
        </subtasks>
      </task>

      <task name="refresh.shortcut.icon" condition="$[desktop.shortcuts:addAclAllUsersDesktopShortcut]=true" allowMultipleInstances="true" typename="@RefreshShortcut" critical="false">
       <dependencies list="remove.iconcache.db,acl.link"/>
        <parameters>
          <parameter name="special.folder.name" value="${desktop}"/>
          <parameter name="link.name" value="$[desktop.shortcuts:key]"/>
          <parameter name="icon.fullpath" value="$[desktop.shortcuts:icon]"/>

        </parameters>
      </task>

    </foreach>

    <task name="kill.explorer2" condition="${windows.version.major}=6" typename="@KillProcess">
      <dependencies list="remove.iconcache.db"/>
      <parameters>
        <parameter name="process" value="explorer"/>
      </parameters>
    </task>


  </tasks>
</taskrunner>